<?php
session_start();
$folio=$_GET['folio'];
$serie=$_GET['serie'];
$sesion="cfd".$folio.trim($serie);
$id_folio=strtok($sesion,"$");
$rfcc=strtok("$");
$nom=strtok($sesion,"$");
$nom.=strtok("$");
$nom.=strtok("$");
$nom.=strtok("$");
$numcte=$_SESSION['cvecliente'];
include('enletras.php');
$V=new EnLetras();

Require("templates/comunxls.php");

$conexion=Obtener_Conexion();
  // $consulta="select convert_to(cad_xml,'SQL_ASCII') as xml from cfd_xml_sellado_y_verificado where numdocto=$folio and serie='$serie'";
   $consulta="SET CLIENT_ENCODING TO 'UNICODE'; select cad_xml as xml from cfd_xml_sellado_y_verificado where numdocto=$folio and serie='$serie'";
   $result=pg_query($conexion,$consulta) or die("fallo consulta ".$consulta); 
   if(!result){echo "error";}
   $valret= pg_num_rows($result);
   $content= pg_fetch_result($result,xml);
      if($valret==0){print "<b><font color='#FF0000' size='5'>Error:</font>No se encontro la factura consulte a su adminístrador.</b><br>";
												exit();}
  $xml=utf8_encode(trim($content));

  $sxml = simplexml_load_string($xml);
  //obtiene fecha vencimiento
  $consulta="select fechaven from cxcfacturas where numdocto=".$folio;
  $result=pg_query($conexion,$consulta) or die("fallo consulta ".$consulta); 
   if(!result){echo "error";}
   $valret= pg_num_rows($result);
   $fechaven= pg_fetch_result($result,fechaven);
   $fechaven= substr($fechaven,0 ,4 )."-".substr($fechaven,4,2)."-".substr($fechaven,6);
      
  //obtiene embarque
  $consulta="select f.nom_corto  from cxcsemaforos s, cxcfletes f  where s.origen=f.fletera and  numdocto=".$folio;
$result=pg_query($conexion,$consulta) or die("fallo consulta ".$consulta); 
   if(!result){echo "error";}
   $valret= pg_num_rows($result);
   $embarque= pg_fetch_result($result,nom_corto);
      
// print_r($sxml);
 function xml_attribute($object, $attribute)
{
    if(isset($object[$attribute]))
        return (string) $object[$attribute];
}

?>

<?php
// seccion encabezado
echo "<table border=1 RULES=NONE FRAME=BOX>";
echo "<tr><td><img src=\"img/logomorsa2.jpg\"></td><td>";
echo "  <table><tr><td>TIPO DE DOCUMENTO </td><td>Factura</td></tr>";
echo "        <tr><td>SERIE - FOLIO </td><td>".xml_attribute($sxml,'serie')." ".xml_attribute($sxml,'folio')."</td></tr>";
echo "        <tr><td>FECHA Y HORA </td><td>".xml_attribute($sxml,'fecha')."</td></tr>";
echo "        <tr><td>LUGAR EXPEDICION</td><td>".xml_attribute($sxml->Emisor->ExpedidoEn,'localidad')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'estado')."</td></tr>";
echo "        <tr><td>A&Ntilde;O Y NO DE EXPEDICION</td><td>".xml_attribute($sxml,'anoAprobacion')." ".xml_attribute($sxml,'noAprobacion')."</td></tr>";
echo "       <tr><td>NO. DE CERTIFICADO </td><td>".xml_attribute($sxml,'noCertificado')."</td></tr>";
echo "  </table>";
echo "</td></tr>";
echo "<tr><td>".xml_attribute($sxml->Emisor->ExpedidoEn,'calle')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'noExterior')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'colonia')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'localidad')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'estado')."</td>";
echo "<td>FECHA VENCIMIENTO ".$fechaven."</td></tr>";
// Seccion datos cliente, embarque y condiciones
echo "<tr><td>";
echo "  <table border=1 RULES=NONE FRAME=BOX width=100%>" ;
echo "     <tr><td><strong>CLIENTE:</strong>   ".$numcte." ".xml_attribute($sxml->Receptor,'nombre')."</td></tr>";
echo "     <tr><td><strong>DOMICILIO:</strong> ".xml_attribute($sxml->Receptor->Domicilio,'calle')." ".xml_attribute($sxml->Receptor->Domicilio,'noExterior')." ".xml_attribute($sxml->Receptor->Domicilio,'colonia')."</td></tr>";
echo "     <tr><td><strong>POBLACION:</strong> ".xml_attribute($sxml->Receptor->Domicilio,'municipio')." ".xml_attribute($sxml->Receptor->Domicilio,'estado')."</td></tr>";
echo "     <tr><td><strong>RFC:</strong>       ".xml_attribute($sxml->Receptor,'rfc')."&nbsp;&nbsp;&nbsp;&nbsp; <strong>CODIGO POSTAL:</strong> ".xml_attribute($sxml->Receptor->Domicilio,'codigoPostal')."</td></tr>";
echo "  </table>";
echo "</td><td><table width=100% CELLPADDING=13 CELLSPACING=5 border=1 RULES=COLS FRAME=BOX ><tr><td>EMBARQUE</td><td>CONDICIONES</td></tr>";
echo "<tr><td>$embarque</td><td>".xml_attribute($sxml,'condicionesDePago')."</td></tr></table></td>";
// Seccion Conceptos
echo "<tr><td colspan=3>";
echo "   <table width=100% border=1 rules='cols' frame=box CELLPADDING=3 CELLSPACING=3>";
echo "      <tr><td width=10%>&nbsp;</td><td width=20% >&nbsp;</td><td width=40%>&nbsp;</td><td width=15%>&nbsp;</td><td width=15%>&nbsp;</td></tr>";

echo "      <tr><td width=10%><strong>CANTIDAD</strong></td><td width=20% ><strong>NO. DE PIEZA</strong></td><td width=40%><strong>DESCRIPCION</strong></td><td width=15%><strong>PRECIO UNITARIO</strong></td><td width=15%><strong>IMPORTE</strong></td></tr>";
echo "      <tr><td width=10%>&nbsp;</td><td width=20% >&nbsp;</td><td width=40%>&nbsp;</td><td width=15%>&nbsp;</td><td width=15%>&nbsp;</td></tr>";

echo " </td></tr></table><tr><td colspan=3> ";
echo "   <table width=100% HEIGHT=30 border=1 rules='cols' frame=box CELLPADDING=3>";

// varios conceptos
          echo "<tr><td width=10%>&nbsp;</td><td width=20%>&nbsp;</td><td width=40%>&nbsp;</td><td width=15%>&nbsp;</td><td width=15%>&nbsp;</td></tr>";

     foreach ($sxml->Conceptos->Concepto as $concepto):
        $cantidad=xml_attribute($concepto,'cantidad'); // declaracion de variables
        $codart=xml_attribute($concepto,'noIdentificacion');
        $unidad=xml_attribute($concepto,'unidad');
        $descripcion=xml_attribute($concepto,'descripcion');
        $importe=xml_attribute($concepto,'importe');
        $valorunitario=xml_attribute($concepto,'valorUnitario');
          echo "<tr><td width=10% height=10px>".$cantidad."</td><td width=20%>$codart</td><td width=40%>$descripcion</td><td width=15% align=right>$valorunitario</td><td width=15% align=right>$importe</td></tr>";
     endforeach;
          echo "<tr><td width=10%>&nbsp;</td><td width=20%>&nbsp;</td><td width=40%>&nbsp;</td><td width=15%>&nbsp;</td><td width=15%>&nbsp;</td></tr>";
          echo "<tr><td width=10%>&nbsp;</td><td width=20%>&nbsp;</td><td width=40%>&nbsp;</td><td width=15%>&nbsp;</td><td width=15%>&nbsp;</td></tr>";
          echo "<tr><td width=10%>&nbsp;</td><td width=20%>&nbsp;</td><td width=40%>&nbsp;</td><td width=15%>&nbsp;</td><td width=15%>&nbsp;</td></tr>";

echo "</table>";
echo "</td></tr>";
//SECCION TOTALES 
echo "<tr><td colspan=3>";
echo "   <table width=100% border=1 rules='cols' frame=box>";
echo "      <tr><td width=20%><strong>SUMA</strong></td><td width=20% ><strong>DESCUENTO</strong></td><td width=20%><strong>SUB-TOTAL</strong></td><td width=20%><strong>I.V.A.</strong></td><td width=20%><strong>TOTAL</strong></td></tr>";
echo "      <tr><td width=20%>&nbsp;</td><td width=20% >&nbsp;</td><td width=20%>&nbsp;</td><td width=20%>&nbsp;</td><td width=20%>&nbsp;</td></tr>";
$suma=floatval(xml_attribute($sxml,'subTotal'))-floatval(xml_attribute($sxml,'descuento'));
echo "      <tr><td width=20% align=center>".xml_attribute($sxml,'subTotal')."</td><td width=20% align=center>".xml_attribute($sxml,'descuento')."</td><td width=20% align=center>".$suma."</td><td width=20% align=center>".xml_attribute($sxml->Impuestos->Traslados->Traslado,'importe')."</td><td width=20% align=center>".xml_attribute($sxml,'total')."</td></tr>";
echo "      <tr><td width=20%>&nbsp;</td><td width=20% >&nbsp;</td><td width=20%>&nbsp;</td><td width=20%>&nbsp;</td><td width=20%>&nbsp;</td></tr>";
echo "   </table>";
echo "</td></tr>";
// Cantidad con letra
echo "<tr><td colspan=3>";
echo "   <table width=100% border=1 rules=none frame=box>";
echo "      <tr><td> <strong>CANTIDAD CON LETRA:</strong></td></tr>";
$letras=$V->ValorEnLetras(floatval(xml_attribute($sxml,'total')),"pesos");
echo "      <tr><td>".$letras."</td></tr>";
echo "   </table>";
echo "</td></tr>";

// Cadena Original
$nombrearchivo=xml_attribute($sxml,'serie').xml_attribute($sxml,'folio');
$cadenaoriginal="||".xml_attribute($sxml,'version');
$cadenaoriginal.="|".xml_attribute($sxml,'serie');
$cadenaoriginal.="|".xml_attribute($sxml,'folio');
$cadenaoriginal.="|".xml_attribute($sxml,'fecha');
$cadenaoriginal.="|".xml_attribute($sxml,'noAprobacion');
$cadenaoriginal.="|".xml_attribute($sxml,'anoAprobacion');
$cadenaoriginal.="|".xml_attribute($sxml,'tipoDeComprobante');
$cadenaoriginal.="|".xml_attribute($sxml,'formaDePago');
$cadenaoriginal.="|".xml_attribute($sxml,'condicionesDePago');
$cadenaoriginal.="|".xml_attribute($sxml,'subTotal');
$cadenaoriginal.="|".xml_attribute($sxml,'descuento');
$cadenaoriginal.="|".xml_attribute($sxml,'total');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor,'rfc');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor,'nombre');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'calle');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'noExterior');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'colonia');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'localidad');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'municipio');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'estado');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'pais');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'codigoPostal');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'calle');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'noExterior');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'referencia');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'colonia');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'localidad');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'municipio');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'estado');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'pais');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'codigoPostal');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor,'rfc');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor,'nombre');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'calle');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'noExterior');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'colonia');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'localidad');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'municipio');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'estado');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'pais');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'codigoPostal');
    foreach ($sxml->Conceptos->Concepto as $concepto):
        $cantidad=xml_attribute($concepto,'cantidad'); 
        $codart=xml_attribute($concepto,'noIdentificacion');
        $unidad=xml_attribute($concepto,'unidad');
        $descripcion=xml_attribute($concepto,'descripcion');
        $importe=xml_attribute($concepto,'importe');
        $valorunitario=xml_attribute($concepto,'valorUnitario');
          $cadenaoriginal.= "|".$cantidad."|$codart|$descripcion|$valorunitario|$importe";
     endforeach;


$cadenaoriginal.="|".xml_attribute($sxml->Impuestos->Traslados->Traslado,'impuesto');
$cadenaoriginal.="|".xml_attribute($sxml->Impuestos->Traslados->Traslado,'tasa');
$cadenaoriginal.="|".xml_attribute($sxml->Impuestos->Traslados->Traslado,'importe');

$cadenaoriginal.="||";
echo "<tr><td colspan=3>";
echo "   <table width=100% border=0 rules=none frame=box>";
echo "      <tr><td> &nbsp;</td></tr>";
echo "      <tr><td> <strong>CADENA ORIGINAL</strong></td></tr>";
echo "      <tr><td><font size=2>$cadenaoriginal</font></td></tr>";
echo "      <tr><td> &nbsp;</td></tr>";
echo "   </table>";
echo "</td></tr>";
// Sello Digital
echo "<tr><td colspan=3>";
echo "   <table width=100% border=0 rules=none frame=box>";
echo "      <tr><td> &nbsp;</td></tr>";
echo "      <tr><td width=10%> <strong>SELLO DIGITAL</strong></td><td><font size=2>".xml_attribute($sxml,'sello')."</font></td></tr>";
echo "      <tr><td> &nbsp;</td></tr>";
echo "   </table>";
echo "</td></tr>";

//pie factura
echo "<tr><td colspan=3>";
echo "   <table border=0 width=100%>";
echo "      <tr><td> &nbsp;</td></tr>";
echo "      <tr><td align=center>Este documento es una representaci&oacute;n impresa de un CFD </td></tr>";
echo "      <tr><td> &nbsp;</td></tr>";
echo "   </table>";
echo "</td></tr>";
echo "</table>";


/*****************/
// seccion encabezado
$strContent= "<html><body>\n ";
$strContent= "<table border=0 RULES=NONE FRAME=BOX CELLPADDING=0 CELLSPACING=0 >";
$strContent.= " \n<tr><td width=60%><img src='http://".$_SERVER["SERVER_NAME"]."/morsa/img/logomorsa11.jpg' w‏idth='200px' heigth='86px'><br><font size=1 color=#1A0062>";
$strContent.= xml_attribute($sxml->Emisor,'nombre')."<br>";
$strContent.= "Domicilio Fiscal ".xml_attribute($sxml->Emisor->DomicilioFiscal,'calle')." ";
$strContent.= xml_attribute($sxml->Emisor->DomicilioFiscal,'noExterior')." ";
$strContent.= xml_attribute($sxml->Emisor->DomicilioFiscal,'referencia')." ";
$strContent.= xml_attribute($sxml->Emisor->DomicilioFiscal,'colonia')."<br>";
$strContent.= "CP. ".xml_attribute($sxml->Emisor->DomicilioFiscal,'codigoPostal')." TELS (667) 758-20-00 ";
$strContent.= xml_attribute($sxml->Emisor->DomicilioFiscal,'localidad')." ";
$strContent.= xml_attribute($sxml->Emisor->DomicilioFiscal,'estado')."<br>";
$strContent.="Sitio web www.morsa.com.mx<br>DOMICILIO ESTABLECIMIENTO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".xml_attribute($sxml->Emisor,'rfc')."</font>";
$strContent.="</td><td width=40%>";
$strContent.= "  <table border=0 CELLPADDING=0 CELLSPACING=0><tr><td><font size=1>TIPO DE DOCUMENTO</td><td> <b>Factura </b></td></tr>";
$strContent.= "       <tr><td> SERIE - FOLIO </td><td><b>".xml_attribute($sxml,'serie')." - ".xml_attribute($sxml,'folio')."</b></td></tr>";
$strContent.= "       <tr><td> FECHA Y HORA </td><td><b>".xml_attribute($sxml,'fecha')."</b></td></tr>";
$strContent.= "       <tr><td> LUGAR EXPEDICION </td><td><b>".xml_attribute($sxml->Emisor->ExpedidoEn,'localidad')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'estado')."</b></td></tr>";
$strContent.= "       <tr><td> A&Ntilde;O Y NO DE EXPEDICION </td><td><b>".xml_attribute($sxml,'anoAprobacion')." - ".xml_attribute($sxml,'noAprobacion')."</b></td></tr>";
$strContent.= "       <tr><td>NO. DE CERTIFICADO </td><td><b> ".xml_attribute($sxml,'noCertificado')."</b></td></tr></table>";
$strContent.= "  </font>";
$strContent.= "</td></tr>";
$strContent.= "<tr><td><font size=1>".xml_attribute($sxml->Emisor->ExpedidoEn,'calle')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'noExterior')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'colonia')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'localidad')." ".xml_attribute($sxml->Emisor->ExpedidoEn,'estado')."</font></td>";
$strContent.= "<td><font size=1>FECHA VENCIMIENTO ".$fechaven."</font></td></tr>";
// Seccion datos cliente, embarque y condiciones
$strContent.= "<tr><td>";
$strContent.= "  <table border=0 RULES=NONE CELLPADDING=0 CELLSPACING=0 FRAME=BOX width=100%>" ;
$strContent.= "     <tr><td><font size=1><strong>CLIENTE:</strong>   ".$numcte." ".xml_attribute($sxml->Receptor,'nombre')."</td></tr>";
$strContent.= "     <tr><td><strong>DOMICILIO:</strong> ".xml_attribute($sxml->Receptor->Domicilio,'calle')." ".xml_attribute($sxml->Receptor->Domicilio,'noExterior')." ".xml_attribute($sxml->Receptor->Domicilio,'colonia')."</td></tr>";
$strContent.= "     <tr><td><strong>POBLACION:</strong> ".xml_attribute($sxml->Receptor->Domicilio,'municipio')." ".xml_attribute($sxml->Receptor->Domicilio,'estado')."</td></tr>";
$strContent.= "     <tr><td><strong>RFC:</strong>       ".xml_attribute($sxml->Receptor,'rfc')."&nbsp;&nbsp;&nbsp;&nbsp; <strong>CODIGO POSTAL:</strong> ".xml_attribute($sxml->Receptor->Domicilio,'codigoPostal')."</font></td></tr>";
$strContent.= "  </table>";
$strContent.= "</td><td><table width=100% CELLPADDING=8 CELLSPACING=4 border=1 RULES=COLS FRAME=BOX ><tr><td><font size=1>EMBARQUE</td><td>CONDICIONES</td></tr>";
$strContent.= "<tr><td>$embarque</td><td>".xml_attribute($sxml,'condicionesDePago')."<font size=1></td></tr></table></td>";
// Seccion Conceptos
$strContent.= "<tr><td colspan=3>";
$strContent.= "   <table width=100% border=1 rules='cols' frame=box CELLPADDING=1 CELLSPACING=0>";
$strContent.= "      <tr><td width=10%><strong>CANTIDAD</strong></td><td width=20% ><strong>NO. DE PIEZA</strong></td><td width=40%><strong>DESCRIPCION</strong></td><td width=15%><strong>PRECIO UNITARIO</strong></td><td width=15%><strong>IMPORTE</strong></td></tr>";
$strContent.= " </td></tr></table><tr><td colspan=3> ";
$strContent.= "   <table width=100%  HEIGHT=10 border=0 rules='cols' frame=box CELLPADDING=0 CELLSPACING=0>";

// varios conceptos

     foreach ($sxml->Conceptos->Concepto as $concepto):
        $cantidad=xml_attribute($concepto,'cantidad'); // declaracion de variables
        $codart=xml_attribute($concepto,'noIdentificacion');
        $unidad=xml_attribute($concepto,'unidad');
        $descripcion=xml_attribute($concepto,'descripcion');
        $importe=xml_attribute($concepto,'importe');
        $valorunitario=xml_attribute($concepto,'valorUnitario');
          $strContent.= "<tr><td width=10% HEIGHT=2%>".$cantidad."</td><td width=20%>$codart</td><td width=40%>$descripcion</td><td width=15% align=right>$valorunitario</td><td width=15% align=right>$importe</td></tr>";
     endforeach;
         // $strContent.= "<tr><td width=10%>&nbsp;</td><td width=20%>&nbsp;</td><td width=40%>&nbsp;</td><td width=15%>&nbsp;</td><td width=15%>&nbsp;</td></tr>";

$strContent.= "</table>";
$strContent.= "</td></tr>";
//SECCION TOTALES 
$strContent.= "<tr><td colspan=3>";
$strContent.= "   <table width=100% border=1 rules='cols' CELLPADDING=1 CELLSPACING=0 frame=box>";
$strContent.= "      <tr><td width=20%><strong>SUMA</strong></td><td width=20% ><strong>DESCUENTO</strong></td><td width=20%><strong>SUB-TOTAL</strong></td><td width=20%><strong>I.V.A.</strong></td><td width=20%><strong>TOTAL</strong></td></tr>";
$suma=floatval(xml_attribute($sxml,'subTotal'))-floatval(xml_attribute($sxml,'descuento'));
$strContent.= "      <tr><td width=20% height=20px align=center>".xml_attribute($sxml,'subTotal')."</td><td width=20% align=center>".xml_attribute($sxml,'descuento')."</td><td width=20% align=center>".$suma."</td><td width=20% align=center>".xml_attribute($sxml->Impuestos->Traslados->Traslado,'importe')."</td><td width=20% align=center>".xml_attribute($sxml,'total')."</td></tr>";
$strContent.= "   </table>";
$strContent.= "</td></tr>";
// Cantidad con letra
$strContent.= "<tr><td colspan=3>";
$strContent.= "   <table width=100% border=0 rules=none frame=box CELLPADDING=1 CELLSPACING=1>";
$strContent.= "      <tr><td><font size=1> <strong>CANTIDAD CON LETRA:</strong></td></tr>";
$strContent.= "      <tr><td>".$letras."</font></td></tr>";
$strContent.= "   </table>";
$strContent.= "</td></tr>";

// Cadena Original
$cadenaoriginal="||".xml_attribute($sxml,'version');
$cadenaoriginal.="|".xml_attribute($sxml,'serie');
$cadenaoriginal.="|".xml_attribute($sxml,'folio');
$cadenaoriginal.="|".xml_attribute($sxml,'fecha');
$cadenaoriginal.="|".xml_attribute($sxml,'noAprobacion');
$cadenaoriginal.="|".xml_attribute($sxml,'anoAprobacion');
$cadenaoriginal.="|".xml_attribute($sxml,'tipoDeComprobante');
$cadenaoriginal.="|".xml_attribute($sxml,'formaDePago');
$cadenaoriginal.="|".xml_attribute($sxml,'condicionesDePago');
$cadenaoriginal.="|".xml_attribute($sxml,'subTotal');
$cadenaoriginal.="|".xml_attribute($sxml,'descuento');
$cadenaoriginal.="|".xml_attribute($sxml,'total');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor,'rfc');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor,'nombre');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'calle');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'noExterior');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'colonia');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'localidad');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'municipio');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'estado');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'pais');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->ExpedidoEn,'codigoPostal');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'calle');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'noExterior');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'referencia');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'colonia');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'localidad');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'municipio');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'estado');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'pais');
$cadenaoriginal.="|".xml_attribute($sxml->Emisor->DomicilioFiscal,'codigoPostal');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor,'rfc');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor,'nombre');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'calle');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'noExterior');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'colonia');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'localidad');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'municipio');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'estado');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'pais');
$cadenaoriginal.="|".xml_attribute($sxml->Receptor->Domicilio,'codigoPostal');
    foreach ($sxml->Conceptos->Concepto as $concepto):
        $cantidad=xml_attribute($concepto,'cantidad'); 
        $codart=xml_attribute($concepto,'noIdentificacion');
        $unidad=xml_attribute($concepto,'unidad');
        $descripcion=xml_attribute($concepto,'descripcion');
        $importe=xml_attribute($concepto,'importe');
        $valorunitario=xml_attribute($concepto,'valorUnitario');
          $cadenaoriginal.= "|".$cantidad."|$codart|$descripcion|$valorunitario|$importe";
     endforeach;


$cadenaoriginal.="|".xml_attribute($sxml->Impuestos->Traslados->Traslado,'impuesto');
$cadenaoriginal.="|".xml_attribute($sxml->Impuestos->Traslados->Traslado,'tasa');
$cadenaoriginal.="|".xml_attribute($sxml->Impuestos->Traslados->Traslado,'importe');

$cadenaoriginal.="||";
$strContent.= "<tr><td colspan=3>";
$strContent.= "   <table width=100% border=0 rules=none frame=box CELLPADDING=0 CELLSPACING=1>";
$strContent.= "      <tr><td><font size=1> <strong>CADENA ORIGINAL</strong></td></tr>";
$strContent.= "      <tr><td>$cadenaoriginal</font></td></tr>";
$strContent.= "   </table>";
$strContent.= "</td></tr>";
// Sello Digital
$strContent.= "<tr><td colspan=3>";
$strContent.= "   <table width=100% border=0 rules=none frame=box CELLPADDING=0 CELLSPACING=1>";
$strContent.= "      <tr><td width=10%><font size=1> <strong>SELLO DIGITAL</strong></td><td>".xml_attribute($sxml,'sello')."</font></td></tr>";
$strContent.= "   </table>";
$strContent.= "</td></tr>";

//pie factura
$strContent.= "<tr><td colspan=3>";
$strContent.= "   <table border=0 width=100% CELLPADDING=0 CELLSPACING=1>";
$strContent.= "      <tr><td align=center>Este documento es una representaci&oacute;n impresa de un CFD </td></tr>";
$strContent.= "   </table>";
$strContent.= "</td></tr>";
$strContent.= "</table>";
$strContent.= "</body></html>";

exec("pwd",$output,$return);

$command="java HtmlToPDF \"$output[0]/lista/".$nombrearchivo."\" \"".$strContent."\"";
//echo "java HtmlToPDF \"$output[0]/lista/".$nombrearchivo.".pdf\" \"<html><body>prueba html to pdf</body></html>\" <br>";
exec($command,$output, $return);
echo "<br><a href='lista/".$nombrearchivo.".pdf' >Bajar Factura en PDF</a>";
?>


